package com.gift.recommendation.modules.admin.controller;

import com.gift.recommendation.Base.BaseResponse;
import com.gift.recommendation.Base.PageData;
import com.gift.recommendation.config.TokenPass;
import com.gift.recommendation.modules.admin.biz.GoodsImpl;
import com.gift.recommendation.modules.admin.dto.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zzh <2658137258@qq.com>
 * @date 2023/2/2
 */
@RestController
@RequestMapping("/gift/goods")
@Api(tags = "商品管理")
@Validated
public class GoodsController {

    @Autowired
    private GoodsImpl goods;

    @ApiOperation(value = "添加商品")
    @RequestMapping(path = "/add",method = RequestMethod.POST)
    public BaseResponse goodsAdd(@RequestBody GoodsReq req){
        goods.addGoods(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "设置轮播图")
    @RequestMapping(path = "/add-rotograph",method = RequestMethod.POST)
    public BaseResponse addRotograph(@RequestBody GoodsReq req){
        goods.addRotograph(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "取消轮播图")
    @RequestMapping(path = "/delete-rotograph",method = RequestMethod.POST)
    public BaseResponse deleteRotograph(@RequestBody GoodsReq req){
        goods.deleteRotograph(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "修改商品")
    @RequestMapping(path = "/update",method = RequestMethod.POST)
    public BaseResponse goodsUpdate(@RequestBody GoodsReq req){
        goods.updateGoods(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "商品入库")
    @RequestMapping(path = "/storage",method = RequestMethod.POST)
    public BaseResponse storage(@RequestBody GoodsReq req){
        goods.storage(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "删除商品")
    @RequestMapping(path = "/delete",method = RequestMethod.POST)
    public BaseResponse goodsDelete(@RequestParam Long id){
        goods.goodsDelete(id);
        return BaseResponse.success();
    };

    @ApiOperation(value = "根据id查找商品")
    @TokenPass
    @RequestMapping(path = "/get",method = RequestMethod.POST)
    public BaseResponse goodsSearchById(@RequestParam Long id){
        GoodsRsp result = goods.goodsSearchById(id);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "商品列表")
    @RequestMapping(path = "/list",method = RequestMethod.POST)
    @TokenPass
    public BaseResponse<PageData<GoodsEntityRsp>> goodsList(@RequestBody GoodsListReq req){
        PageData<GoodsEntityRsp> result = goods.goodsList(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "给出当前用户的猜你喜欢")
    @RequestMapping(path = "/guess-like-no-point",method = RequestMethod.POST)
    public BaseResponse<List<GoodsEntityRsp>> guessLikeNoPoint(@RequestBody GuessLikeReq req){
        List<GoodsEntityRsp> result = goods.guessLikeNoPoint(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "商品信息统计")
    @RequestMapping(path = "/sales-status",method = RequestMethod.POST)
    public BaseResponse<PageData<GoodsSaleStatusRsp>> goodsSaleStatus(@RequestBody GoodsSaleStatusReq req){
        PageData<GoodsSaleStatusRsp> result = goods.goodsSaleStatus(req);
        return BaseResponse.success(result);
    };
}
